﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ADECMS.UserPages
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
  //  [WebService(Namespace = "http://tempuri.org/")]
  //  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AvatarHandler : IHttpHandler
    {
        ADECMSDBDataContext cmsdb;
        public void ProcessRequest(HttpContext context)
        {
            String uname = context.Request.QueryString["uname"];
            try
            {
                cmsdb = new ADECMSDBDataContext();
                USER kor = cmsdb.USERs.Single(k => k.username == uname);
                byte[] slika = kor.USER_OPTION.avatar.ToArray();
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(slika);
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
